package com.wc.alorithm_blue_bridge._数据结构.树状数组.拳头对决;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/29 12:40
 * @description
 * https://www.lanqiao.cn/problems/20272/learning/?contest_id=250
 */
public class Main {
    /**
     * 思路：
     * 红队上的场上人数越多, 因为每一个数只能互相比一次, 那大的往后放才能比较的更多
     * 所以蓝队要从小往大上场
     * 选用树状数组来存储红色上场的
     * 用离散化离散 1 ~ 10^9的数
     * 剩下遍历即可
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1;
    static int[] a = new int[N], b = new int[N], c = new int[M];
    static int[] tr = new int[M];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) c[i] = b[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) c[n + i] = a[i] = sc.nextInt();
        // 离散化
        Arrays.sort(c, 1, 2 * n + 1);
        m = 0;
        for (int i = 1; i <= 2 * n; i++) {
            if (c[i] != c[i - 1]) c[++m] = c[i];
        }
        Arrays.sort(b, 1, n + 1);
        long res = 0;
        for (int i = 1; i <= n; i++) {
            add(get(a[i]));
            int j = get(b[i]);
            if (j - 1 >= 1) res += query(j - 1);
        }
        out.println(res);
        out.flush();
    }

    static void add(int x) {
        // >=
        for (int i = x; i <= m; i += lowbit(i)) tr[i]++;
    }

    static int query(int x) {
        int res = 0;
        for (int i = x; i > 0; i -= lowbit(i)) {
            res += tr[i];
        }
        return res;
    }

    static int get(int x) {
        int l = 1, r = m;
        while (l < r) {
            int mid = l + r >> 1;
            if (c[mid] >= x) r = mid;
            else l = mid + 1;
        }
        return l;
    }

    static int lowbit(int x) {
        return x & -x;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

